﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;

namespace WAContratos.Manager
{
    public class cls_datos
    {
        OracleCommand Comm = new OracleCommand();
        OracleDataReader Cread;
        OracleConnection odbcConn = new OracleConnection();


        public OracleConnection conect()
        {
            try
            {
                OracleConnection cone = new OracleConnection();
                if(cone.State== ConnectionState.Closed)
                {
                    //'DatMapConnectionString1()
                    //'cone.ConnectionString = "FILEDSN=" & System.AppDomain.CurrentDomain.BaseDirectory & "App_Data\conect.dsn;"
                    cone.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString3"].ToString();
                    //'"FILEDSN=" & System.AppDomain.CurrentDomain.BaseDirectory & "bdsys\conect.dsn;"
                    //'"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents and Settings\usuario\Mis documentos\actualizacioncarmonitor\CARMONITOR\CARMONITOR - Copy\CARMONITOR\bin\Debug\bdsys\DatMap.mdf;integrated security=sspi;Connect Timeout=30;User Instance=True"
                    //' '"Driver={SQL Server};server=(local);uid=sa;pwd=sql2005;wsid=OSWALDO;database=DATMAP"
                }
                return cone;
            }catch (Exception ex)
            {
                return null;
            }
        }

    public DataSet datasetd(String query)
    {
        DataSet dt = new DataSet();
        OracleConnection con = new OracleConnection();
        try
        {
            con = conect();
            con.Open();
            OracleCommand Comm = new OracleCommand();
            Comm = con.CreateCommand();
            Comm.CommandText = query;
            OracleDataReader dtread;
            dtread = Comm.ExecuteReader();
            DataTable dtat = new DataTable();
            dtat.Load(dtread);
            dtat.TableName = "datasetload";
            dt.Tables.Add(dtat);
            //'dt.Load(dtread, LoadOption.Upsert, dtat)
            Comm.Dispose();
            con.Close();
            return dt;

        }catch (Exception ex)
        {
            return dt;
        }
        
    }

    public DataSet datasetadd(String query)
    {
        DataSet dt = new DataSet();
        OracleConnection con = new OracleConnection();
        
        try
        {
            con = conect();
            con.Open();
            OracleCommand Comm = new OracleCommand();
            Comm = con.CreateCommand();
            Comm.CommandText = query;
            OracleDataAdapter dtadp = new OracleDataAdapter();

            dtadp.TableMappings.Add("Table", "tbladap");
            dtadp.SelectCommand = Comm;
            dtadp.Fill(dt);
            con.Close();
            return dt;
        }catch (Exception ex)
        {
            return dt;
        }


    }

    public Boolean insertaq(String query)
    {
        OracleConnection con = new OracleConnection();
        try
        {
            con = conect();
            con.Open();
            OracleCommand Comm = new OracleCommand();
            Comm = con.CreateCommand();
            Comm.CommandText = query;
            Comm.ExecuteNonQuery();
            con.Close();
            return true;
        }
        catch (OracleException ex)
        {
            return false;
        }
    }

    }
}
